<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('角色管理')"/>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>角色列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <form id="roleForm" th:action="@{/sys/role/list}" class="form-inline">
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <div class="input-group-btn">
                                        <button data-toggle="dropdown" class="btn btn-white dropdown-toggle"
                                                type="button">角色名称
                                        </button>
                                    </div>
                                    <input type="text" class="form-control" th:value="${roleName}" name="roleName"
                                           placeholder="角色名称" />
                                    <input type="hidden" id="roleId" name="roleId">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <button id="roleButton" type="submit" class="btn btn-primary" onclick="">
                                    <i class="fa fa-search"></i>&nbsp;查询
                                </button>
                            </div>
                        </form>
                    </div>
                    <div class="row">
                        <div class="tool-div" role="group">
                            <button shiro:hasPermission="sys:role:save" type="button"
                                    class="btn btn-primary button-margin" onclick="toAdd()">
                                <i class="fa fa-plus"></i>&nbsp;新增
                            </button>
                            <button shiro:hasPermission="sys:role:update" type="button"
                                    class="btn btn-primary button-margin" onclick="toEdit()">
                                <i class="fa fa-edit"></i>&nbsp;编辑
                            </button>
                            <button shiro:hasPermission="sys:role:delete" type="button"
                                    class="btn btn-primary button-margin" onclick="deleteRole()">
                                <i class="fa fa-remove"></i>&nbsp;删除
                            </button>
                        </div>
                    </div>
                    <table id="role">
                    </table>
                    <div id="rolePager"></div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Page-Level Scripts -->
<script type="text/javascript">

    var searcher = Searcher.create('#role',
        [
            {name: 'roleId', hidden: true},
            {label: "角色名称", name:"roleName", index:"roleName", width:100, sortable:false},
            {label: "所属部门",name:"deptName", index: "deptName", width: 80,sortable: false},
            {label: "备注",name:"remark", index: "remark", width: 80,sortable: false},
            {label: "创建时间", name:"createTime", index:"createTime", width:100, sortable:false}
        ],
        {
            rownumbers: false,multiselect: true
        }
    );

    /**
     * 跳转至新增页
     */
    function toAdd() {
        var index = Dialog.openUrl("新增", ctxPath + '/modules/sys/role/role_add.html',{area : ['900px','700px'],
            maxmin: true,
            end: function() {
                searcher.query($('#role').getGridParam('page'));
            }
        });
        layer.full(index);
    }

    /**
     * 编辑
     */
    function toEdit() {
        var rowDatas = searcher.getSelectedRows("roleId");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑");
            return;
        }
        var index = Dialog.openUrl("编辑", ctxPath + '/sys/role/toEdit/'+rowDatas,{area : ['900px','650px'], end: function () {
                searcher.query($('#role').getGridParam('page'));
            }  });
        layer.full(index);
    }

    function deleteRole() {
        var rowDatas = searcher.getSelectedRows("roleId");
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行");
            return;
        }
        Dialog.confirm('确定删除？', function(index){
            Page.ajaxPOST(ctxPath + "/sys/role/delete", {roleIds: rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcher.query($('#roleForm').getGridParam('page'));
                });
            });
        });
    }

</script>
</body>
</html>